using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VDICQUER
    {
        public DataRow Convert2DICQUER(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryDICQUER(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["DQSPRKZ"] = " ".PadRight(2 ); 
         dwReturn["DQDICLFD"] = " ".PadRight(0 ); 
         dwReturn["DQMASKE"] = " ".PadRight(10 ); 
         dwReturn["DQFKZ"] = " ".PadRight(2 ); 
         dwReturn["DQUGRP"] = " ".PadRight(8 ); 
         dwReturn["DQFOLGENR"] = " ".PadRight(2 ); 
         dwReturn["DQLFD"] = " ".PadRight(0 ); 
         dwReturn["DQZ"] = " ".PadRight(0 ); 
         dwReturn["DQS"] = " ".PadRight(0 ); 
         dwReturn["DQLAE"] = " ".PadRight(0 ); 
         dwReturn["DQPLATZ"] = " ".PadRight(0 ); 
         dwReturn["DQLR"] = " ".PadRight(1 ); 
         dwReturn["DQHERKUNFT"] = " ".PadRight(1 ); 
         dwReturn["DQZUSATZ1"] = " ".PadRight(4 ); 
         dwReturn["DQZUSATZ2"] = " ".PadRight(1 ); 
         dwReturn["DQFILLER"] = " ".PadRight(4 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapDICQUER(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveDICQUER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryDICQUER(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapDICQUER(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertDICQUER(dwLocal, ITXDBVERSION);
            }
            UpdateDICQUER(dwLocal);
        }
        public void InsertDICQUER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO DICQUER(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryDICQUER(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM DICQUER WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM DICQUER  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "DICQUER";
            Return = Result;
            return Return;
        }
        public void DeleteDICQUER(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM DICQUER   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateDICQUER(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE DICQUER SET "
                    +"DQSPRKZ= :DQSPRKZ,"
                    +"DQDICLFD= :DQDICLFD,"
                    +"DQMASKE= :DQMASKE,"
                    +"DQFKZ= :DQFKZ,"
                    +"DQUGRP= :DQUGRP,"
                    +"DQFOLGENR= :DQFOLGENR,"
                    +"DQLFD= :DQLFD,"
                    +"DQZ= :DQZ,"
                    +"DQS= :DQS,"
                    +"DQLAE= :DQLAE,"
                    +"DQPLATZ= :DQPLATZ,"
                    +"DQLR= :DQLR,"
                    +"DQHERKUNFT= :DQHERKUNFT,"
                    +"DQZUSATZ1= :DQZUSATZ1,"
                    +"DQZUSATZ2= :DQZUSATZ2,"
                    +"DQFILLER= :DQFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("DQSPRKZ", OracleType.NVarChar).Value = dwData["DQSPRKZ"].ToString(); 
          or1.Parameters.Add("DQDICLFD", OracleType.NVarChar).Value = dwData["DQDICLFD"].ToString(); 
          or1.Parameters.Add("DQMASKE", OracleType.NVarChar).Value = dwData["DQMASKE"].ToString(); 
          or1.Parameters.Add("DQFKZ", OracleType.NVarChar).Value = dwData["DQFKZ"].ToString(); 
          or1.Parameters.Add("DQUGRP", OracleType.NVarChar).Value = dwData["DQUGRP"].ToString(); 
          or1.Parameters.Add("DQFOLGENR", OracleType.NVarChar).Value = dwData["DQFOLGENR"].ToString(); 
          or1.Parameters.Add("DQLFD", OracleType.NVarChar).Value = dwData["DQLFD"].ToString(); 
          or1.Parameters.Add("DQZ", OracleType.NVarChar).Value = dwData["DQZ"].ToString(); 
          or1.Parameters.Add("DQS", OracleType.NVarChar).Value = dwData["DQS"].ToString(); 
          or1.Parameters.Add("DQLAE", OracleType.NVarChar).Value = dwData["DQLAE"].ToString(); 
          or1.Parameters.Add("DQPLATZ", OracleType.NVarChar).Value = dwData["DQPLATZ"].ToString(); 
          or1.Parameters.Add("DQLR", OracleType.NVarChar).Value = dwData["DQLR"].ToString(); 
          or1.Parameters.Add("DQHERKUNFT", OracleType.NVarChar).Value = dwData["DQHERKUNFT"].ToString(); 
          or1.Parameters.Add("DQZUSATZ1", OracleType.NVarChar).Value = dwData["DQZUSATZ1"].ToString(); 
          or1.Parameters.Add("DQZUSATZ2", OracleType.NVarChar).Value = dwData["DQZUSATZ2"].ToString(); 
          or1.Parameters.Add("DQFILLER", OracleType.NVarChar).Value = dwData["DQFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
